package com.groupbuying.customer.service.impl;

import com.groupbuying.customer.service.SmsService;
import com.groupbuying.customer.utils.SmsUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author gxy
 * @Description 发送短信业务逻辑
 * @Date 2019/5/27 10:05
 **/

@Service
public class SmsServiceImpl  implements SmsService{
    @Override
    public boolean sendSms(Map<String, String> params) {
        boolean flag = false;
        if(params.get("mobile") != null && !"".equals(params.get("mobile")) && params.get("mobile") != null && !"".equals(params.get("mobile"))){
           flag =  SmsUtils.sendSms(params.get("mobile"),params.get("content"));
        }
        return flag;
    }

    @Override
    public boolean sendCodeForRegister(String mobile, String code){
        StringBuffer sb = new StringBuffer();
        sb.append("验证码：");
        sb.append(code);
        sb.append("，您正在通过手机注册。30分钟内有效，请勿泄露。如非本人操作，请忽略本短信。");
        Map contentMap = new HashMap();
        contentMap.put("mobile",mobile);
        contentMap.put("content", sb.toString());
        return this.sendSms(contentMap);
    }

    @Override
    public boolean sendCodeForFindPwd(String mobile, String code){
        StringBuffer sb = new StringBuffer();
        sb.append("验证码：");
        sb.append(code);
        sb.append("，您正在通过手机找回密码。30分钟内有效，请勿泄露。");
        Map contentMap = new HashMap();
        contentMap.put("mobile",mobile);
        contentMap.put("content", sb.toString());
        return this.sendSms(contentMap);
    }

}
